package com.leoren.run.activity.share;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.amap.api.maps.model.LatLng;
import com.bumptech.glide.Glide;
import com.leoren.run.R;
import com.leoren.run.common.Const;
import com.leoren.run.log.L;
import com.leoren.run.utils.GsonUtil;
import com.leoren.run.utils.MyMapUtils;
import com.leoren.run.utils.ScreenShotUtils;
import com.leoren.run.utils.ToastUtil;
import com.leoren.run.utils.trace.PathUtils;
import com.leoren.run.vo.ShareDataVo;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 根据跑步记录生成图片界面
 */
public class GenSharePicActivity extends AppCompatActivity implements View.OnClickListener {

    private Toolbar toolbar;
    private ImageView backImg;
    private CircleImageView headImg;
    private TextView usernameText;
    private TextView dateText;
    private TextView distanceText;
    private TextView timeText;
    private Button shareBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gen_share_pic);

        initLayout();
    }

    private void initLayout(){
        toolbar = findViewById(R.id.gen_share_toolbar);

        backImg = findViewById(R.id.map_route_pic);
        headImg = findViewById(R.id.share_head_img);
        usernameText = findViewById(R.id.share_username_text);
        dateText = findViewById(R.id.share_date);
        distanceText = findViewById(R.id.share_distance_text);
        timeText = findViewById(R.id.share_time_text);

        shareBtn = findViewById(R.id.share_btn);

        shareBtn.setOnClickListener(this);

        initDate();
    }

    /**
     * 初始化各控件信息
     */
    private void initDate(){
        Intent intent = getIntent();
        String runMapStr = intent.getStringExtra(Const.START_SHARE);
        ShareDataVo shareVo = GsonUtil.formatJsonToShareDateVo(runMapStr);
        Glide.with(this).load(shareVo.getBackUrl()).into(backImg);
        Glide.with(this).load(shareVo.getHeadUrl()).into(headImg);
        usernameText.setText(shareVo.getUsername());
        dateText.setText(shareVo.getDateTime());
        distanceText.setText(shareVo.getDistance() + "KM");
        timeText.setText(shareVo.getTime());

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.share_btn:
                startShare();
                break;
            default:
                break;
        }
    }

    /**
     * 开始发布分享
     */
    private void startShare(){
        boolean isSuccess = ScreenShotUtils.shotScreen(this);
        if(isSuccess){
            L.e("截屏成功");
            Intent intent = new Intent(this, PublishCommentActivity.class);
            startActivity(intent);
        }else {
            ToastUtil.MakeToast("截屏失败");
        }
    }
}
